#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    model = new QSqlTableModel(this);
    model->setTable("非标滤光片库存");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->setSort(0,Qt::DescendingOrder);
    model->select(); //选取整个表的所有行
//    ui->tableView->verticalHeader()->hide();
//    std::cout<<model->rowCount()<<std::endl;
    ui->tableView->setModel(model);
    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_2_clicked()
{
    close();
}

void MainWindow::on_pushButton_clicked()
{
    QString Filter_temp;
    Filter_temp = "波长 = ";
    Filter_temp.append(ui->lineEdit->text());

    model->setTable("非标滤光片库存");
    model->setFilter(Filter_temp);
    model->setSort(0,Qt::DescendingOrder);
    model->select();
    ui->tableView->setModel(model);
    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}

void MainWindow::on_pushButton_3_clicked()
{
    model->setTable("非标滤光片库存");
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->setSort(0,Qt::DescendingOrder);
    model->select(); //选取整个表的所有行
//    ui->tableView->verticalHeader()->hide();
//    std::cout<<model->rowCount()<<std::endl;
    ui->tableView->setModel(model);
    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
